package com.mediacloud.app.newsmodule.activity.military_encyclopedia

import android.util.TypedValue
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.mediacloud.app.newsmodule.R

class MilitaryEncyclopediaInfoRelationAdapter : BaseQuickAdapter<EntryInfoRelationList,BaseViewHolder>(R.layout.item_bk_info_relation) {
    var zoom: Int = 0

    override fun convert(helper: BaseViewHolder, item:EntryInfoRelationList) {
        val tvKey = helper.getView<TextView>(R.id.tvKey)
        val tvValue = helper.getView<TextView>(R.id.tvValue)
        tvKey.text = item.attributeCode
        tvValue.text = item.attributeValue
        if (zoom != 0){
            val textSize: Float = tvKey.context.resources.getDimension(R.dimen.sp_18) * (zoom / 100f)
            tvKey.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize)
            tvValue.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize)
        }
    }

    private var mIsShowOnlyCount = false

    /**
     * 设置显示的条数
     */
    fun setShowOnlyCount(isShowOnly: Boolean) {
        mIsShowOnlyCount = isShowOnly
        notifyDataSetChanged()
    }

    override fun getItemCount(): Int {
        return if (mIsShowOnlyCount) if (super.getItemCount() > 5) 5 else super.getItemCount() else super.getItemCount()
    }

    fun resizeText(zoom: Int){
        this.zoom = zoom
        notifyDataSetChanged()
    }
}